package tyx.study.jsp.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DBUtil {
	public static ResultSet query(String sql,Object ...params) {
			Connection conn=null;
			PreparedStatement ps=null;
	        try{
	            conn= DSUtils.getConnection();
	            ps=conn.prepareStatement(sql);
	            for ( int i = 0; i < params.length; i++ ) {
	                ps.setObject(i+1,params[i]);
	            }
	            ResultSet rs= ps.executeQuery();
	            return rs;
	        }
	        catch (Exception e){
	            e.printStackTrace();
	        }
	        finally {
	           }
	        return null;	 
	}
	public static Integer update(String sql,Object ...params) {
		  Connection conn=null;
	       PreparedStatement ps=null;
	        try{
	            conn=DSUtils.getConnection();
	            ps=conn.prepareStatement(sql);
	            for ( int i = 0; i < params.length; i++ ) {
	                ps.setObject(i+1,params[i]);
	            }
	            return ps.executeUpdate();
	        }
	        catch (Exception e){
	            e.printStackTrace();
	        }
	        finally {
	           }
	        return 0;	   
	}
	
}
